<?php

function getLoadingImage($params=array())
{
    $img=HTTP_IMAGE.'data/loadingIcon.gif';
    $data_url='';
    $name='';
    $div_id='';
    $div_class='';
    $img_id='loading-img';
    $img_class='load';
    if($params){
        $img=isset($params['img_src']) ? $params['img_src'] : $img;
        $name=isset($params['name']) ? ' name="'.$params['name'].'"' : '';
        $data_url=isset($params['data_url']) ? ' data-url="'.$params['data_url'].'"' : '';
        $div_id=isset($params['div_id']) ? ' id="'.$params['div_id'].'"' : $div_id;
        $div_class=isset($params['div_class']) ? ' class="'.$params['div_class'].'"' : $div_class;
        $img_id=isset($params['img_id']) ? ' id="'.$params['img_id'].'"' : $img_id;
        $img_class=isset($params['img_class']) ? ' class="'.$params['img_class'].'"' : $img_class;
    }

    return '<div'.$div_id.$div_class.'><img'.$img_id.$img_class.$data_url.' src="'.$img.'"'.$name.' /></div>';
}

function getAjaxButton($params=array())
{
    $text='Go!';
    $name='';
    $data_url='';
    $div_id='';
    $div_class='';
    $span_id='';
    $span_class='';
    $autofocus='';
    if($params){
        $text=isset($params['button_text']) ? $params['button_text'] : $text;
        $name=isset($params['name']) ? ' name="'.$params['name'].'"' : '';
        $data_url=isset($params['data_url']) ? ' data-url="'.$params['data_url'].'"' : '';
        $div_id=isset($params['div_id']) ? ' id="'.$params['div_id'].'"' : $div_id;
        $div_class=isset($params['div_class']) ? ' class="'.$params['div_class'].'"' : $div_class;
        $span_id=isset($params['span_id']) ? ' id="'.$params['span_id'].'"' : $span_id;
        $span_class=isset($params['span_class']) ? ' class="'.$params['span_class'].'"' : $span_class;
        $autofocus=isset($params['autofocus']) && $params['autofocus']===true ? ' autofocus="true"' : '';
    }

    return '<div'.$div_id.$div_class.'><a href="'.$data_url.'" onclick="return false;"'.$span_id.$span_class.$name.$data_url.$autofocus.'>'.$text.'</a></div>';
}

function getSubmitButton($params=array())
{
    $button_type='input';
    $type='submit';
    $text='';
    $name='';
    $value='';
    $data_url='';
    $div_id='';
    $div_class='';
    $button_id='';
    $button_class='';
    $autofocus='';
    if($params){
        $button_type=isset($params['button_type']) ? $params['button_type'] : $button_type;
        $type=isset($params['type']) ? ' type="'.$params['type'].'"' : ' type="'.$type.'"';
        $text=isset($params['button_text']) ? $params['button_text'] : '';
        $name=isset($params['name']) ? ' name="'.$params['name'].'"' : '';
        $value=isset($params['value']) ? ' value="'.$params['value'].'"' : '';
        $data_url=isset($params['data_url']) ? ' data-url="'.$params['data_url'].'"' : '';
        $div_id=isset($params['div_id']) ? ' id="'.$params['div_id'].'"' : $div_id;
        $div_class=isset($params['div_class']) ? ' class="'.$params['div_class'].'"' : $div_class;
        $button_id=isset($params['button_id']) ? ' id="'.$params['button_id'].'"' : $button_id;
        $button_class=isset($params['button_class']) ? ' class="'.$params['button_class'].'"' : $button_class;
        $autofocus=isset($params['autofocus']) && $params['autofocus']===true ? ' autofocus="true"' : '';
    }

    return $text ? '<div'.$div_id.$div_class.'><'.$button_type.$type.$button_id.$button_class.$name.$value.$data_url.'>'.$text.'</'.$button_type.'></div>' :
        '<div'.$div_id.$div_class.'><'.$button_type.$type.$button_id.$button_class.$name.$value.$data_url.$autofocus.' /></div>';
}

function getUrl($params=array())
{
    $href=isset($params['href']) ? $params['href'] : '#';
    $text=isset($params['text']) ? $params['text'] : '';
    $link_id=isset($params['link_id']) ? ' id="'.$params['link_id'].'"' : '';
    $link_class=isset($params['link_class']) ? ' class="'.$params['link_class'].'"' : ' class="text-decoration-none"';
    $container=isset($params['container']) ? $params['container'] : false;
    $container_id=isset($params['container_id']) ? ' id="'.$params['container_id'].'"' : '';
    $container_class=isset($params['container_class']) ? ' class="'.$params['container_class'].'"' : '';
    $data_url=isset($params['data_url']) ? ' data-url="'.$params['data_url'].'"' : '';
    $data_id=isset($params['data_id']) ? ' data-id="'.$params['data_id'].'"' : '';
    $name=isset($params['name']) ? $params['name'].' ' : '';
    $on_click=isset($params['on_click']) ? ' onclick="'.$params['on_click'].'"' : '';

    $link='<a'.$link_id.$link_class.$data_id.' href="'.$href.'"'.$on_click.'>'.$text."</a>";

    if(!$container) return $link;

    return '<'.$container.$container_id.$container_class.$data_url.$data_id.'>'.$name.$link.'</'.$container.'>';
}